#!/bin/bash

# 检查参数数量
if [ "$#" -ne 1 ]; then
    echo "Usage: source $0 <input_file>"
    return 1
fi

input_file="$1"

# 检查文件是否存在
if [ ! -f "$input_file" ]; then
    echo "Error: Input file '$input_file' not found"
    echo "Usage: source $0 <input_file>"
    return 1
fi

# 提取第一个匹配的worker_id
worker_id=$(grep -oE 'VLLM_WORKER_ID: [0-9]+' "$input_file" | grep -oE '[0-9]+' | head -1)

# 检查是否成功提取
if [ -z "$worker_id" ]; then
    echo "Error: No VLLM_WORKER_ID found in '$input_file'"
    echo "Usage: source $0 <input_file>"
    return 1
fi

echo "Extracted VLLM_WORKER_ID: $worker_id"

# 设置环境变量并执行kvclient
export VLLM_WORKER_ID=${worker_id}
